package com.xszx.serviceedu.controller;


import com.xszx.commonutils.R;
import com.xszx.serviceedu.entity.vo.SubjectNestedVo;
import com.xszx.serviceedu.service.SubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author 白熊
 * @since 2024-07-15
 */
@RestController
@RequestMapping("/serviceedu/subject")
@Api(tags="课程分类管理")
//@CrossOrigin //跨域
public class SubjectController {

    @Autowired
    private SubjectService subjectService;

    @ApiOperation(value = "嵌套数据列表")
    @GetMapping//获取课程分类的一级分类以及二级分类
    public R nestedList(){
        List<SubjectNestedVo> subjectNestedVoList = subjectService.nestedList();
        return R.ok().data("items", subjectNestedVoList);
    }
    //添加课程分类
    @ApiOperation(value = "Excel批量导入")
    @PostMapping("addSubject")
    public R addSubject(MultipartFile file) {
        //1 获取上传的excel文件 MultipartFile
        //返回错误提示信息
        subjectService.batchImport(file,subjectService);
        return R.ok().message("导入成功");
    }
}
